package com.jufanshare.tokenjwt.controller;

import com.jufanshare.tokenjwt.common.result.Result;
import com.jufanshare.tokenjwt.conf.JwtInterceptor;
import io.jsonwebtoken.Claims;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/backend")
public class TestJwtController {
    /**
     * 测试接口
     * @return
     */
    @GetMapping("/test")
    public Result test(HttpServletRequest request){

        Claims claims = (Claims) request.getAttribute(JwtInterceptor.USER_INFO_KEY);
        return Result.ok("接口请求成功，jwt中的用户信息userName是："+(claims.get("userName").toString()));
    }
}
